<template>
	<view class="index">
		<s-tab :categoryId="categoryId" @change="changeTab"></s-tab>
		<s-menus ref="SMenus"></s-menus>
		<sdc-back></sdc-back>
	</view>
</template>

<script>
	import STab from './components/index/s-tab.vue'
	import SMenus from './components/index/s-menus.vue'
	export default {
		data() {
			return {
				categoryId: null,
				tab: {}
			};
		},
		components: {
			STab,
			SMenus
		},
		methods: {
			changeTab({tab}){
				this.tab = tab
				this.$refs.SMenus.reload(tab.id)
			}
		},
		onPullDownRefresh() {
			Promise.all([
				this.$refs.SMenus.reload(this.tab.id)
			])
			.then(()=>{
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			this.$refs.SMenus.nextPage()
		},
		onReady() {
			this.categoryId = this.$Route.query.id
			let category = this.menuCategory.find(item=>{
				return item.id == this.categoryId
			})
			if(category !== undefined && category.childlist.length > 0){
				this.tab = category.childlist[0]
				this.$refs.SMenus.reload(category.childlist[0].id)
			}
		}
	}
</script>

<style lang="scss">

</style>
